import storage from '@/utils/storage'

const key = 'sidebarState'

const state = {
  toggleState: storage.get(key) || 'full'
}

const mutations = {
  setToggleState: (state, toggleState) => {
    state.toggleState = toggleState
    storage.set(key, toggleState)
  }
}

const actions = {
  toggleHandler({ commit }) {
    let toggleState = ''
    storage.get(key) === 'collapse' ? (toggleState = 'full') : (toggleState = 'collapse')
    commit('setToggleState', toggleState)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
